home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / src / gas-211 / gas / config / tc-sparc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  38.1 KB  |  1,817 lines

  1. /* tc-sparc.c -- Assemble for the SPARC
  2.    Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  19.  
  20. #define cypress 1234
  21.  
  22. #include <stdio.h>
  23. #include <ctype.h>
  24.  
  25. #include "as.h"
  26.  
  27. /* careful, this file includes data *declarations* */
  28. #include "opcode/sparc.h"
  29.  
  30. void md_begin ();
  31. void md_end ();
  32. void md_number_to_chars ();
  33. void md_assemble ();
  34. char *md_atof ();
  35. void md_create_short_jump ();
  36. void md_create_long_jump ();
  37. int md_estimate_size_before_relax ();
  38. void md_ri_to_chars ();
  39. symbolS *md_undefined_symbol ();
  40. static void sparc_ip ();
  41.  
  42. static enum sparc_architecture current_architecture = v6;
  43. static int architecture_requested;
  44. static int warn_on_bump;
  45.  
  46. extern int target_big_endian;
  47.  
  48. const relax_typeS md_relax_table[1];
  49.  
  50. /* handle of the OPCODE hash table */
  51. static struct hash_control *op_hash = NULL;
  52.  
  53. static void s_seg (), s_proc (), s_data1 (), s_reserve (), s_common ();
  54. extern void s_globl (), s_long (), s_short (), s_space (), cons ();
  55. extern void s_align_bytes (), s_ignore ();
  56.  
  57. /* Ugly hack to keep non-BFD version working.  */
  58. #ifndef BFD_ASSEMBLER
  59. #define BFD_RELOC_NONE        NO_RELOC
  60. #define BFD_RELOC_32        RELOC_32
  61. #define BFD_RELOC_HI22        RELOC_HI22
  62. #define BFD_RELOC_LO10        RELOC_LO10
  63. #define BFD_RELOC_SPARC_WDISP22    RELOC_WDISP22
  64. #define BFD_RELOC_32_PCREL_S2    RELOC_WDISP30
  65. #define BFD_RELOC_SPARC22    RELOC_22
  66. #define BFD_RELOC_SPARC_BASE13    RELOC_BASE13
  67. #define BFD_RELOC_SPARC13    RELOC_13
  68. #define BFD_RELOC_SPARC_BASE22    RELOC_BASE22
  69. #define subseg_set        subseg_new
  70. #endif
  71.  
  72. const pseudo_typeS md_pseudo_table[] =
  73. {
  74.   {"align", s_align_bytes, 0},    /* Defaulting is invalid (0) */
  75.   {"common", s_common, 0},
  76.   {"global", s_globl, 0},
  77.   {"half", cons, 2},
  78.   {"optim", s_ignore, 0},
  79.   {"proc", s_proc, 0},
  80.   {"reserve", s_reserve, 0},
  81.   {"seg", s_seg, 0},
  82.   {"skip", s_space, 0},
  83.   {"word", cons, 4},
  84.   {NULL, 0, 0},
  85. };
  86.  
  87. const int md_short_jump_size = 4;
  88. const int md_long_jump_size = 4;
  89. const int md_reloc_size = 12;    /* Size of relocation record */
  90.  
  91. /* This array holds the chars that always start a comment.  If the
  92.    pre-processor is disabled, these aren't very useful */
  93. const char comment_chars[] = "!";    /* JF removed '|' from comment_chars */
  94.  
  95. /* This array holds the chars that only start a comment at the beginning of
  96.    a line.  If the line seems to have the form '# 123 filename'
  97.    .line and .file directives will appear in the pre-processed output */
  98. /* Note that input_file.c hand checks for '#' at the beginning of the
  99.    first line of the input file.  This is because the compiler outputs
  100.    #NO_APP at the beginning of its output. */
  101. /* Also note that comments started like this one will always
  102.    work if '/' isn't otherwise defined. */
  103. const char line_comment_chars[] = "#";
  104.  
  105. const char line_separator_chars[] = "";
  106.  
  107. /* Chars that can be used to separate mant from exp in floating point nums */
  108. const char EXP_CHARS[] = "eE";
  109.  
  110. /* Chars that mean this number is a floating point constant */
  111. /* As in 0f12.456 */
  112. /* or    0d1.2345e12 */
  113. const char FLT_CHARS[] = "rRsSfFdDxXpP";
  114.  
  115. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  116.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  117.    but nothing is ideal around here.
  118.    */
  119.  
  120. static unsigned char octal[256];
  121. #define isoctal(c)  octal[c]
  122. static unsigned char toHex[256];
  123.  
  124. struct sparc_it
  125.   {
  126.     char *error;
  127.     unsigned long opcode;
  128.     struct nlist *nlistp;
  129.     expressionS exp;
  130.     int pcrel;
  131. #ifdef BFD_ASSEMBLER
  132.     bfd_reloc_code_real_type reloc;
  133. #else
  134.     enum reloc_type reloc;
  135. #endif
  136.   };
  137.  
  138. struct sparc_it the_insn, set_insn;
  139.  
  140. #if 0
  141. static void print_insn PARAMS ((struct sparc_it *insn));
  142. #endif
  143. static int getExpression PARAMS ((char *str));
  144.  
  145. static char *expr_end;
  146. static int special_case;
  147.  
  148. /*
  149.  * Instructions that require wierd handling because they're longer than
  150.  * 4 bytes.
  151.  */
  152. #define    SPECIAL_CASE_SET    1
  153. #define    SPECIAL_CASE_FDIV    2
  154.  
  155. /*
  156.  * sort of like s_lcomm
  157.  *
  158.  */
  159. static int max_alignment = 15;
  160.  
  161. static void
  162. s_reserve ()
  163. {
  164. #ifndef OBJ_AOUT
  165.   as_fatal ("s_reserve only defined for a.out");
  166. #else
  167.   char *name;
  168.   char *p;
  169.   char c;
  170.   int align;
  171.   int size;
  172.   int temp;
  173.   symbolS *symbolP;
  174.  
  175.   name = input_line_pointer;
  176.   c = get_symbol_end ();
  177.   p = input_line_pointer;
  178.   *p = c;
  179.   SKIP_WHITESPACE ();
  180.  
  181.   if (*input_line_pointer != ',')
  182.     {
  183.       as_bad ("Expected comma after name");
  184.       ignore_rest_of_line ();
  185.       return;
  186.     }
  187.  
  188.   ++input_line_pointer;
  189.  
  190.   if ((size = get_absolute_expression ()) < 0)
  191.     {
  192.       as_bad ("BSS length (%d.) <0! Ignored.", size);
  193.       ignore_rest_of_line ();
  194.       return;
  195.     }                /* bad length */
  196.  
  197.   *p = 0;
  198.   symbolP = symbol_find_or_make (name);
  199.   *p = c;
  200.  
  201.   if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0)
  202.     {
  203.       as_bad ("bad .reserve segment: `%s'", input_line_pointer);
  204.       return;
  205.     }                /* if not bss */
  206.  
  207.   input_line_pointer += 6;
  208.   SKIP_WHITESPACE ();
  209.  
  210.   if (*input_line_pointer == ',')
  211.     {
  212.       ++input_line_pointer;
  213.  
  214.       SKIP_WHITESPACE ();
  215.       if (*input_line_pointer == '\n')
  216.     {
  217.       as_bad ("Missing alignment");
  218.       return;
  219.     }
  220.  
  221.       align = get_absolute_expression ();
  222.       if (align > max_alignment)
  223.     {
  224.       align = max_alignment;
  225.       as_warn ("Alignment too large: %d. assumed.", align);
  226.     }
  227.       else if (align < 0)
  228.     {
  229.       align = 0;
  230.       as_warn ("Alignment negative. 0 assumed.");
  231.     }
  232.  
  233.       record_alignment (bss_section, align);
  234.  
  235.       /* convert to a power of 2 alignment */
  236.       for (temp = 0; (align & 1) == 0; align >>= 1, ++temp);;
  237.  
  238.       if (align != 1)
  239.     {
  240.       as_bad ("Alignment not a power of 2");
  241.       ignore_rest_of_line ();
  242.       return;
  243.     }            /* not a power of two */
  244.  
  245.       align = temp;
  246.     }                /* if has optional alignment */
  247.   else
  248.     align = 0;
  249.  
  250.   if (S_GET_OTHER (symbolP) == 0
  251.       && S_GET_DESC (symbolP) == 0
  252.       && (S_GET_SEGMENT (symbolP) == bss_section
  253.       || !S_IS_DEFINED (symbolP)))
  254.     {
  255.       if (! need_pass_2)
  256.     {
  257.       char *p;
  258.       segT current_seg = now_seg;
  259.       subsegT current_subseg = now_subseg;
  260.  
  261.       subseg_set (bss_section, 1); /* switch to bss */
  262.  
  263.       if (align)
  264.         frag_align (align, 0); /* do alignment */
  265.  
  266.       /* detach from old frag */
  267.       if (S_GET_SEGMENT(symbolP) == bss_section)
  268.         symbolP->sy_frag->fr_symbol = NULL;
  269.  
  270.       symbolP->sy_frag = frag_now;
  271.       p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
  272.             size, (char *)0);
  273.       *p = 0;
  274.  
  275.       S_SET_SEGMENT (symbolP, bss_section);
  276.  
  277.       subseg_set (current_seg, current_subseg);
  278.     }
  279.     }
  280.   else
  281.     {
  282.       as_warn("Ignoring attempt to re-define symbol %s.", name);
  283.     }                /* if not redefining */
  284.  
  285.   demand_empty_rest_of_line ();
  286. #endif
  287. }
  288.  
  289. static void
  290. s_common ()
  291. {
  292.   register char *name;
  293.   register char c;
  294.   register char *p;
  295.   register int temp;
  296.   register symbolS *symbolP;
  297.  
  298.   name = input_line_pointer;
  299.   c = get_symbol_end ();
  300.   /* just after name is now '\0' */
  301.   p = input_line_pointer;
  302.   *p = c;
  303.   SKIP_WHITESPACE ();
  304.   if (*input_line_pointer != ',')
  305.     {
  306.       as_bad ("Expected comma after symbol-name");
  307.       ignore_rest_of_line ();
  308.       return;
  309.     }
  310.   input_line_pointer++;        /* skip ',' */
  311.   if ((temp = get_absolute_expression ()) < 0)
  312.     {
  313.       as_bad (".COMMon length (%d.) <0! Ignored.", temp);
  314.       ignore_rest_of_line ();
  315.       return;
  316.     }
  317.   *p = 0;
  318.   symbolP = symbol_find_or_make (name);
  319.   *p = c;
  320.   if (S_IS_DEFINED (symbolP))
  321.     {
  322.       as_bad ("Ignoring attempt to re-define symbol");
  323.       ignore_rest_of_line ();
  324.       return;
  325.     }
  326.   if (S_GET_VALUE (symbolP) != 0)
  327.     {
  328.       if (S_GET_VALUE (symbolP) != temp)
  329.     {
  330.       as_warn ("Length of .comm \"%s\" is already %d. Not changed to %d.",
  331.            S_GET_NAME (symbolP), S_GET_VALUE (symbolP), temp);
  332.     }
  333.     }
  334.   else
  335.     {
  336.       S_SET_VALUE (symbolP, temp);
  337.       S_SET_EXTERNAL (symbolP);
  338. #ifdef OBJ_ELF
  339.       /* But not for a.out ... find some sensible way to characterize
  340.      this.  */
  341.       S_SET_SEGMENT (symbolP, now_seg);
  342. #endif
  343.     }
  344.   know (symbolP->sy_frag == &zero_address_frag);
  345. #ifdef OBJ_ELF
  346.   if (*input_line_pointer != ',')
  347.     {
  348.       as_bad ("Expected command (and alignment) after common length");
  349.       ignore_rest_of_line ();
  350.       return;
  351.     }
  352.   input_line_pointer++;
  353.   temp = get_absolute_expression ();
  354.   if (temp > max_alignment)
  355.     {
  356.       temp = max_alignment;
  357.       as_warn ("Common alignment too large: %d. assumed", temp);
  358.     }
  359.   else if (temp < 0)
  360.     {
  361.       temp = 0;
  362.       as_warn ("Common alignment negative; 0 assumed");
  363.     }
  364.   record_alignment (S_GET_SEGMENT (symbolP), temp);
  365. #else
  366.   if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
  367.       && strncmp (input_line_pointer, ",\"data\"", 7) != 0)
  368.     {
  369.       p = input_line_pointer;
  370.       while (*p && *p != '\n')
  371.     p++;
  372.       c = *p;
  373.       *p = '\0';
  374.       as_bad ("bad .common segment: `%s'", input_line_pointer);
  375.       *p = c;
  376.       return;
  377.     }
  378.   input_line_pointer += 6 + (input_line_pointer[2] == 'd');    /* Skip either */
  379. #endif
  380.   demand_empty_rest_of_line ();
  381.   return;
  382. }                /* s_common() */
  383.  
  384. static void
  385. s_seg ()
  386. {
  387.  
  388.   if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
  389.     {
  390.       input_line_pointer += 6;
  391.       s_text ();
  392.       return;
  393.     }
  394.   if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
  395.     {
  396.       input_line_pointer += 6;
  397.       s_data ();
  398.       return;
  399.     }
  400.   if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
  401.     {
  402.       input_line_pointer += 7;
  403.       s_data1 ();
  404.       return;
  405.     }
  406.   if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
  407.     {
  408.       input_line_pointer += 5;
  409.       /* We only support 2 segments -- text and data -- for now, so
  410.      things in the "bss segment" will have to go into data for now.
  411.      You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
  412.       subseg_set (data_section, 255);    /* FIXME-SOMEDAY */
  413.       return;
  414.     }
  415.   as_bad ("Unknown segment type");
  416.   demand_empty_rest_of_line ();
  417.   return;
  418. }                /* s_seg() */
  419.  
  420. static void
  421. s_data1 ()
  422. {
  423.   subseg_set (data_section, 1);
  424.   demand_empty_rest_of_line ();
  425.   return;
  426. }                /* s_data1() */
  427.  
  428. static void
  429. s_proc ()
  430. {
  431.   extern char is_end_of_line[];
  432.  
  433.   while (!is_end_of_line[*input_line_pointer])
  434.     {
  435.       ++input_line_pointer;
  436.     }
  437.   ++input_line_pointer;
  438.   return;
  439. }                /* s_proc() */
  440.  
  441.  
  442. /* This function is called once, at assembler startup time.  It should
  443.    set up all the tables, etc. that the MD part of the assembler will need. */
  444. void
  445. md_begin ()
  446. {
  447.   register char *retval = NULL;
  448.   int lose = 0;
  449.   register unsigned int i = 0;
  450.  
  451.   op_hash = hash_new ();
  452.   if (op_hash == NULL)
  453.     as_fatal ("Virtual memory exhausted");
  454.  
  455.   while (i < NUMOPCODES)
  456.     {
  457.       const char *name = sparc_opcodes[i].name;
  458.       retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
  459.       if (retval != NULL && *retval != '\0')
  460.     {
  461.       fprintf (stderr, "internal error: can't hash `%s': %s\n",
  462.            sparc_opcodes[i].name, retval);
  463.       lose = 1;
  464.     }
  465.       do
  466.     {
  467.       if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
  468.         {
  469.           fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
  470.                sparc_opcodes[i].name, sparc_opcodes[i].args);
  471.           lose = 1;
  472.         }
  473.       ++i;
  474.     }
  475.       while (i < NUMOPCODES
  476.          && !strcmp (sparc_opcodes[i].name, name));
  477.     }
  478.  
  479.   if (lose)
  480.     as_fatal ("Broken assembler.  No assembly attempted.");
  481.  
  482.   for (i = '0'; i < '8'; ++i)
  483.     octal[i] = 1;
  484.   for (i = '0'; i <= '9'; ++i)
  485.     toHex[i] = i - '0';
  486.   for (i = 'a'; i <= 'f'; ++i)
  487.     toHex[i] = i + 10 - 'a';
  488.   for (i = 'A'; i <= 'F'; ++i)
  489.     toHex[i] = i + 10 - 'A';
  490.  
  491.  
  492.   target_big_endian = 1;
  493. }                /* md_begin() */
  494.  
  495. void
  496. md_end ()
  497. {
  498.   return;
  499. }                /* md_end() */
  500.  
  501. void
  502. md_assemble (str)
  503.      char *str;
  504. {
  505.   char *toP;
  506.   int rsd;
  507.  
  508.   know (str);
  509.   sparc_ip (str);
  510.  
  511.   /* See if "set" operand is absolute and small; skip sethi if so. */
  512.   if (special_case == SPECIAL_CASE_SET
  513.       && the_insn.exp.X_seg == absolute_section)
  514.     {
  515.       if (the_insn.exp.X_add_number >= -(1 << 12)
  516.       && the_insn.exp.X_add_number < (1 << 12))
  517.     {
  518.       the_insn.opcode = 0x80102000    /* or %g0,imm,... */
  519.         | (the_insn.opcode & 0x3E000000)    /* dest reg */
  520.         | (the_insn.exp.X_add_number & 0x1FFF);    /* imm */
  521.       special_case = 0;    /* No longer special */
  522.       the_insn.reloc = BFD_RELOC_NONE;    /* No longer relocated */
  523.     }
  524.     }
  525.  
  526.   toP = frag_more (4);
  527.   /* put out the opcode */
  528.   md_number_to_chars (toP, the_insn.opcode, 4);
  529.  
  530.   /* put out the symbol-dependent stuff */
  531.   if (the_insn.reloc != BFD_RELOC_NONE)
  532.     {
  533.       fix_new (frag_now,    /* which frag */
  534.            (toP - frag_now->fr_literal),    /* where */
  535.            4,        /* size */
  536.            the_insn.exp.X_add_symbol,
  537.            the_insn.exp.X_subtract_symbol,
  538.            the_insn.exp.X_add_number,
  539.            the_insn.pcrel,
  540.            the_insn.reloc);
  541.     }
  542.  
  543.   switch (special_case)
  544.     {
  545.     case SPECIAL_CASE_SET:
  546.       special_case = 0;
  547.       assert (the_insn.reloc == BFD_RELOC_HI22);
  548.       /* See if "set" operand has no low-order bits; skip OR if so. */
  549.       if (the_insn.exp.X_seg == absolute_section
  550.       && ((the_insn.exp.X_add_number & 0x3FF) == 0))
  551.     return;
  552.       toP = frag_more (4);
  553.       rsd = (the_insn.opcode >> 25) & 0x1f;
  554.       the_insn.opcode = 0x80102000 | (rsd << 25) | (rsd << 14);
  555.       md_number_to_chars (toP, the_insn.opcode, 4);
  556.       fix_new (frag_now,    /* which frag */
  557.            (toP - frag_now->fr_literal),    /* where */
  558.            4,        /* size */
  559.            the_insn.exp.X_add_symbol,
  560.            the_insn.exp.X_subtract_symbol,
  561.            the_insn.exp.X_add_number,
  562.            the_insn.pcrel,
  563.            BFD_RELOC_LO10
  564.            );
  565.       return;
  566.  
  567.     case SPECIAL_CASE_FDIV:
  568.       /* According to information leaked from Sun, the "fdiv" instructions
  569.      on early SPARC machines would produce incorrect results sometimes.
  570.      The workaround is to add an fmovs of the destination register to
  571.      itself just after the instruction.  This was true on machines
  572.      with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
  573.       special_case = 0;
  574.       assert (the_insn.reloc == BFD_RELOC_NONE);
  575.       toP = frag_more (4);
  576.       rsd = (the_insn.opcode >> 25) & 0x1f;
  577.       the_insn.opcode = 0x81A00020 | (rsd << 25) | rsd;    /* fmovs dest,dest */
  578.       md_number_to_chars (toP, the_insn.opcode, 4);
  579.       return;
  580.  
  581.     case 0:
  582.       return;
  583.  
  584.     default:
  585.       as_fatal ("failed sanity check.");
  586.     }
  587. }                /* md_assemble() */
  588.  
  589. static void
  590. sparc_ip (str)
  591.      char *str;
  592. {
  593.   char *error_message = "";
  594.   char *s;
  595.   const char *args;
  596.   char c;
  597.   struct sparc_opcode *insn;
  598.   char *argsStart;
  599.   unsigned long opcode;
  600.   unsigned int mask = 0;
  601.   int match = 0;
  602.   int comma = 0;
  603.   long immediate_max = 0;
  604.  
  605.   for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
  606.     ;
  607.   switch (*s)
  608.     {
  609.  
  610.     case '\0':
  611.       break;
  612.  
  613.     case ',':
  614.       comma = 1;
  615.  
  616.       /*FALLTHROUGH */
  617.  
  618.     case ' ':
  619.       *s++ = '\0';
  620.       break;
  621.  
  622.     default:
  623.       as_bad ("Unknown opcode: `%s'", str);
  624.       exit (1);
  625.     }
  626.   if ((insn = (struct sparc_opcode *) hash_find (op_hash, str)) == NULL)
  627.     {
  628.       as_bad ("Unknown opcode: `%s'", str);
  629.       return;
  630.     }
  631.   if (comma)
  632.     {
  633.       *--s = ',';
  634.     }
  635.   argsStart = s;
  636.   for (;;)
  637.     {
  638.       opcode = insn->match;
  639.       memset (&the_insn, '\0', sizeof (the_insn));
  640.       the_insn.reloc = BFD_RELOC_NONE;
  641.  
  642.       /*
  643.        * Build the opcode, checking as we go to make
  644.        * sure that the operands match
  645.        */
  646.       for (args = insn->args;; ++args)
  647.     {
  648.       switch (*args)
  649.         {
  650.  
  651.  
  652.         case 'M':
  653.         case 'm':
  654.           if (strncmp (s, "%asr", 4) == 0)
  655.         {
  656.           s += 4;
  657.  
  658.           if (isdigit (*s))
  659.             {
  660.               long num = 0;
  661.  
  662.               while (isdigit (*s))
  663.             {
  664.               num = num * 10 + *s - '0';
  665.               ++s;
  666.             }
  667.  
  668.               if (num < 16 || 31 < num)
  669.             {
  670.               error_message = ": asr number must be between 15 and 31";
  671.               goto error;
  672.             }    /* out of range */
  673.  
  674.               opcode |= (*args == 'M' ? RS1 (num) : RD (num));
  675.               continue;
  676.             }
  677.           else
  678.             {
  679.               error_message = ": expecting %asrN";
  680.               goto error;
  681.             }        /* if %asr followed by a number. */
  682.  
  683.         }        /* if %asr */
  684.           break;
  685.  
  686.  
  687.         case '\0':        /* end of args */
  688.           if (*s == '\0')
  689.         {
  690.           match = 1;
  691.         }
  692.           break;
  693.  
  694.         case '+':
  695.           if (*s == '+')
  696.         {
  697.           ++s;
  698.           continue;
  699.         }
  700.           if (*s == '-')
  701.         {
  702.           continue;
  703.         }
  704.           break;
  705.  
  706.         case '[':        /* these must match exactly */
  707.         case ']':
  708.         case ',':
  709.         case ' ':
  710.           if (*s++ == *args)
  711.         continue;
  712.           break;
  713.  
  714.         case '#':        /* must be at least one digit */
  715.           if (isdigit (*s++))
  716.         {
  717.           while (isdigit (*s))
  718.             {
  719.               ++s;
  720.             }
  721.           continue;
  722.         }
  723.           break;
  724.  
  725.         case 'C':        /* coprocessor state register */
  726.           if (strncmp (s, "%csr", 4) == 0)
  727.         {
  728.           s += 4;
  729.           continue;
  730.         }
  731.           break;
  732.  
  733.         case 'b':        /* next operand is a coprocessor register */
  734.         case 'c':
  735.         case 'D':
  736.           if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
  737.         {
  738.           mask = *s++;
  739.           if (isdigit (*s))
  740.             {
  741.               mask = 10 * (mask - '0') + (*s++ - '0');
  742.               if (mask >= 32)
  743.             {
  744.               break;
  745.             }
  746.             }
  747.           else
  748.             {
  749.               mask -= '0';
  750.             }
  751.           switch (*args)
  752.             {
  753.  
  754.             case 'b':
  755.               opcode |= mask << 14;
  756.               continue;
  757.  
  758.             case 'c':
  759.               opcode |= mask;
  760.               continue;
  761.  
  762.             case 'D':
  763.               opcode |= mask << 25;
  764.               continue;
  765.             }
  766.         }
  767.           break;
  768.  
  769.         case 'r':        /* next operand must be a register */
  770.         case '1':
  771.         case '2':
  772.         case 'd':
  773.           if (*s++ == '%')
  774.         {
  775.           switch (c = *s++)
  776.             {
  777.  
  778.             case 'f':    /* frame pointer */
  779.               if (*s++ == 'p')
  780.             {
  781.               mask = 0x1e;
  782.               break;
  783.             }
  784.               goto error;
  785.  
  786.             case 'g':    /* global register */
  787.               if (isoctal (c = *s++))
  788.             {
  789.               mask = c - '0';
  790.               break;
  791.             }
  792.               goto error;
  793.  
  794.             case 'i':    /* in register */
  795.               if (isoctal (c = *s++))
  796.             {
  797.               mask = c - '0' + 24;
  798.               break;
  799.             }
  800.               goto error;
  801.  
  802.             case 'l':    /* local register */
  803.               if (isoctal (c = *s++))
  804.             {
  805.               mask = (c - '0' + 16);
  806.               break;
  807.             }
  808.               goto error;
  809.  
  810.             case 'o':    /* out register */
  811.               if (isoctal (c = *s++))
  812.             {
  813.               mask = (c - '0' + 8);
  814.               break;
  815.             }
  816.               goto error;
  817.  
  818.             case 's':    /* stack pointer */
  819.               if (*s++ == 'p')
  820.             {
  821.               mask = 0xe;
  822.               break;
  823.             }
  824.               goto error;
  825.  
  826.             case 'r':    /* any register */
  827.               if (!isdigit (c = *s++))
  828.             {
  829.               goto error;
  830.             }
  831.               /* FALLTHROUGH */
  832.             case '0':
  833.             case '1':
  834.             case '2':
  835.             case '3':
  836.             case '4':
  837.             case '5':
  838.             case '6':
  839.             case '7':
  840.             case '8':
  841.             case '9':
  842.               if (isdigit (*s))
  843.             {
  844.               if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
  845.                 {
  846.                   goto error;
  847.                 }
  848.             }
  849.               else
  850.             {
  851.               c -= '0';
  852.             }
  853.               mask = c;
  854.               break;
  855.  
  856.             default:
  857.               goto error;
  858.             }
  859.           /*
  860.                      * Got the register, now figure out where
  861.                      * it goes in the opcode.
  862.                      */
  863.           switch (*args)
  864.             {
  865.  
  866.             case '1':
  867.               opcode |= mask << 14;
  868.               continue;
  869.  
  870.             case '2':
  871.               opcode |= mask;
  872.               continue;
  873.  
  874.             case 'd':
  875.               opcode |= mask << 25;
  876.               continue;
  877.  
  878.             case 'r':
  879.               opcode |= (mask << 25) | (mask << 14);
  880.               continue;
  881.             }
  882.         }
  883.           break;
  884.  
  885.         case 'e':        /* next operand is a floating point register */
  886.         case 'v':
  887.         case 'V':
  888.  
  889.         case 'f':
  890.         case 'B':
  891.         case 'R':
  892.  
  893.         case 'g':
  894.         case 'H':
  895.         case 'J':
  896.           {
  897.         char format;
  898.  
  899.         if (*s++ == '%'
  900.  
  901.             && ((format = *s) == 'f')
  902.  
  903.             && isdigit (*++s))
  904.           {
  905.  
  906.  
  907.  
  908.             for (mask = 0; isdigit (*s); ++s)
  909.               {
  910.             mask = 10 * mask + (*s - '0');
  911.               }        /* read the number */
  912.  
  913.             if ((*args == 'v'
  914.              || *args == 'B'
  915.              || *args == 'H')
  916.             && (mask & 1))
  917.               {
  918.             break;
  919.               }        /* register must be even numbered */
  920.  
  921.             if ((*args == 'V'
  922.              || *args == 'R'
  923.              || *args == 'J')
  924.             && (mask & 3))
  925.               {
  926.             break;
  927.               }        /* register must be multiple of 4 */
  928.  
  929.             if (format == 'f')
  930.               {
  931.             if (mask >= 32)
  932.               {
  933.                 error_message = ": There are only 32 f registers; [0-31]";
  934.                 goto error;
  935.               }    /* on error */
  936.               }        /* if not an 'f' register. */
  937.           }        /* on error */
  938.  
  939.         switch (*args)
  940.           {
  941.  
  942.           case 'v':
  943.           case 'V':
  944.           case 'e':
  945.             opcode |= RS1 (mask);
  946.             continue;
  947.  
  948.  
  949.           case 'f':
  950.           case 'B':
  951.           case 'R':
  952.             opcode |= RS2 (mask);
  953.             continue;
  954.  
  955.           case 'g':
  956.           case 'H':
  957.           case 'J':
  958.             opcode |= RD (mask);
  959.             continue;
  960.           }        /* pack it in. */
  961.  
  962.         know (0);
  963.         break;
  964.           }            /* float arg */
  965.  
  966.         case 'F':
  967.           if (strncmp (s, "%fsr", 4) == 0)
  968.         {
  969.           s += 4;
  970.           continue;
  971.         }
  972.           break;
  973.  
  974.         case 'h':        /* high 22 bits */
  975.           the_insn.reloc = BFD_RELOC_HI22;
  976.           goto immediate;
  977.  
  978.         case 'l':        /* 22 bit PC relative immediate */
  979.           the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
  980.           the_insn.pcrel = 1;
  981.           goto immediate;
  982.  
  983.         case 'L':        /* 30 bit immediate */
  984.           the_insn.reloc = BFD_RELOC_32_PCREL_S2;
  985.           the_insn.pcrel = 1;
  986.           goto immediate;
  987.  
  988.         case 'n':        /* 22 bit immediate */
  989.           the_insn.reloc = BFD_RELOC_SPARC22;
  990.           goto immediate;
  991.  
  992.         case 'i':        /* 13 bit immediate */
  993.           /* What's the difference between base13 and 13?  */
  994.           the_insn.reloc = BFD_RELOC_SPARC_BASE13;
  995.           immediate_max = 0x0FFF;
  996.  
  997.           /*FALLTHROUGH */
  998.  
  999.         immediate:
  1000.           if (*s == ' ')
  1001.         s++;
  1002.           if (*s == '%')
  1003.         {
  1004.           if ((c = s[1]) == 'h' && s[2] == 'i')
  1005.             {
  1006.               the_insn.reloc = BFD_RELOC_HI22;
  1007.               s += 3;
  1008.             }
  1009.           else if (c == 'l' && s[2] == 'o')
  1010.             {
  1011.               the_insn.reloc = BFD_RELOC_LO10;
  1012.               s += 3;
  1013.             }
  1014.           else
  1015.             break;
  1016.         }
  1017.           /* Note that if the getExpression() fails, we
  1018.          will still have created U entries in the
  1019.          symbol table for the 'symbols' in the input
  1020.          string.  Try not to create U symbols for
  1021.          registers, etc. */
  1022.           {
  1023.         /* This stuff checks to see if the
  1024.            expression ends in +%reg If it does,
  1025.            it removes the register from the
  1026.            expression, and re-sets 's' to point
  1027.            to the right place */
  1028.  
  1029.         char *s1;
  1030.  
  1031.         for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
  1032.  
  1033.         if (s1 != s && isdigit (s1[-1]))
  1034.           {
  1035.             if (s1[-2] == '%' && s1[-3] == '+')
  1036.               {
  1037.             s1 -= 3;
  1038.             *s1 = '\0';
  1039.             (void) getExpression (s);
  1040.             *s1 = '+';
  1041.             s = s1;
  1042.             continue;
  1043.               }
  1044.             else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
  1045.               {
  1046.             s1 -= 4;
  1047.             *s1 = '\0';
  1048.             (void) getExpression (s);
  1049.             *s1 = '+';
  1050.             s = s1;
  1051.             continue;
  1052.               }
  1053.           }
  1054.           }
  1055.           (void) getExpression (s);
  1056.           s = expr_end;
  1057.  
  1058.           /* Check for invalid constant values.  Don't
  1059.          warn if constant was inside %hi or %lo,
  1060.          since these truncate the constant to
  1061.          fit.  */
  1062.           if (immediate_max != 0
  1063.           && the_insn.reloc != BFD_RELOC_LO10
  1064.           && the_insn.reloc != BFD_RELOC_HI22
  1065.           && the_insn.exp.X_add_symbol == 0
  1066.           && the_insn.exp.X_subtract_symbol == 0
  1067.           && the_insn.exp.X_seg == absolute_section
  1068.           && (the_insn.exp.X_add_number > immediate_max
  1069.               || the_insn.exp.X_add_number < ~immediate_max))
  1070.         as_bad ("constant value must be between %ld and %ld",
  1071.             ~immediate_max, immediate_max);
  1072.           /* Reset to prevent extraneous range check.  */
  1073.           immediate_max = 0;
  1074.  
  1075.           continue;
  1076.  
  1077.         case 'a':
  1078.           if (*s++ == 'a')
  1079.         {
  1080.           opcode |= ANNUL;
  1081.           continue;
  1082.         }
  1083.           break;
  1084.  
  1085.         case 'A':
  1086.           {
  1087.         char *push = input_line_pointer;
  1088.         expressionS e;
  1089.  
  1090.         input_line_pointer = s;
  1091.  
  1092.         if (expression (&e) == absolute_section)
  1093.           {
  1094.             opcode |= e.X_add_number << 5;
  1095.             s = input_line_pointer;
  1096.             input_line_pointer = push;
  1097.             continue;
  1098.           }        /* if absolute */
  1099.  
  1100.         break;
  1101.           }            /* alternate space */
  1102.  
  1103.         case 'p':
  1104.           if (strncmp (s, "%psr", 4) == 0)
  1105.         {
  1106.           s += 4;
  1107.           continue;
  1108.         }
  1109.           break;
  1110.  
  1111.         case 'q':        /* floating point queue */
  1112.           if (strncmp (s, "%fq", 3) == 0)
  1113.         {
  1114.           s += 3;
  1115.           continue;
  1116.         }
  1117.           break;
  1118.  
  1119.         case 'Q':        /* coprocessor queue */
  1120.           if (strncmp (s, "%cq", 3) == 0)
  1121.         {
  1122.           s += 3;
  1123.           continue;
  1124.         }
  1125.           break;
  1126.  
  1127.         case 'S':
  1128.           if (strcmp (str, "set") == 0)
  1129.         {
  1130.           special_case = SPECIAL_CASE_SET;
  1131.           continue;
  1132.         }
  1133.           else if (strncmp (str, "fdiv", 4) == 0)
  1134.         {
  1135.           special_case = SPECIAL_CASE_FDIV;
  1136.           continue;
  1137.         }
  1138.           break;
  1139.  
  1140.  
  1141.         case 't':
  1142.           if (strncmp (s, "%tbr", 4) != 0)
  1143.         break;
  1144.           s += 4;
  1145.           continue;
  1146.  
  1147.         case 'w':
  1148.           if (strncmp (s, "%wim", 4) != 0)
  1149.         break;
  1150.           s += 4;
  1151.           continue;
  1152.  
  1153.         case 'y':
  1154.           if (strncmp (s, "%y", 2) != 0)
  1155.         break;
  1156.           s += 2;
  1157.           continue;
  1158.  
  1159.         default:
  1160.           as_fatal ("failed sanity check.");
  1161.         }            /* switch on arg code */
  1162.       break;
  1163.     }            /* for each arg that we expect */
  1164.     error:
  1165.       if (match == 0)
  1166.     {
  1167.       /* Args don't match. */
  1168.       if (((unsigned) (&insn[1] - sparc_opcodes)) < NUMOPCODES
  1169.           && !strcmp (insn->name, insn[1].name))
  1170.         {
  1171.           ++insn;
  1172.           s = argsStart;
  1173.           continue;
  1174.         }
  1175.       else
  1176.         {
  1177.           as_bad ("Illegal operands%s", error_message);
  1178.           return;
  1179.         }
  1180.     }
  1181.       else
  1182.     {
  1183.       if (insn->architecture > current_architecture)
  1184.         {
  1185.           if ((!architecture_requested || warn_on_bump)
  1186.           &&
  1187.           1
  1188.         )
  1189.         {
  1190.           if (warn_on_bump)
  1191.             {
  1192.               as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
  1193.                    architecture_pname[current_architecture],
  1194.                    architecture_pname[insn->architecture],
  1195.                    str);
  1196.             }        /* if warning */
  1197.  
  1198.           current_architecture = insn->architecture;
  1199.         }
  1200.           else
  1201.         {
  1202.           as_bad ("architecture mismatch on \"%s\" (\"%s\").  current architecture is \"%s\"",
  1203.               str,
  1204.               architecture_pname[insn->architecture],
  1205.               architecture_pname[current_architecture]);
  1206.           return;
  1207.         }        /* if bump ok else error */
  1208.         }            /* if architecture higher */
  1209.     }            /* if no match */
  1210.  
  1211.       break;
  1212.     }                /* forever looking for a match */
  1213.  
  1214.   the_insn.opcode = opcode;
  1215.   return;
  1216. }                /* sparc_ip() */
  1217.  
  1218. static int
  1219. getExpression (str)
  1220.      char *str;
  1221. {
  1222.   char *save_in;
  1223.   segT seg;
  1224.  
  1225.   save_in = input_line_pointer;
  1226.   input_line_pointer = str;
  1227.   seg = expression (&the_insn.exp);
  1228.   if (seg == absolute_section
  1229.       || seg == text_section
  1230.       || seg == data_section
  1231.       || seg == bss_section
  1232.       || seg == undefined_section
  1233.       || seg == diff_section
  1234.       || seg == big_section
  1235.       || seg == absent_section)
  1236.     /* ok */;
  1237.   else
  1238.     {
  1239.       the_insn.error = "bad segment";
  1240.       expr_end = input_line_pointer;
  1241.       input_line_pointer = save_in;
  1242.       return 1;
  1243.     }
  1244.   expr_end = input_line_pointer;
  1245.   input_line_pointer = save_in;
  1246.   return 0;
  1247. }                /* getExpression() */
  1248.  
  1249.  
  1250. /*
  1251.   This is identical to the md_atof in m68k.c.  I think this is right,
  1252.   but I'm not sure.
  1253.  
  1254.   Turn a string in input_line_pointer into a floating point constant of type
  1255.   type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  1256.   emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  1257.   */
  1258.  
  1259. /* Equal to MAX_PRECISION in atof-ieee.c */
  1260. #define MAX_LITTLENUMS 6
  1261.  
  1262. char *
  1263. md_atof (type, litP, sizeP)
  1264.      char type;
  1265.      char *litP;
  1266.      int *sizeP;
  1267. {
  1268.   int prec;
  1269.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  1270.   LITTLENUM_TYPE *wordP;
  1271.   char *t;
  1272.   char *atof_ieee ();
  1273.  
  1274.   switch (type)
  1275.     {
  1276.  
  1277.     case 'f':
  1278.     case 'F':
  1279.     case 's':
  1280.     case 'S':
  1281.       prec = 2;
  1282.       break;
  1283.  
  1284.     case 'd':
  1285.     case 'D':
  1286.     case 'r':
  1287.     case 'R':
  1288.       prec = 4;
  1289.       break;
  1290.  
  1291.     case 'x':
  1292.     case 'X':
  1293.       prec = 6;
  1294.       break;
  1295.  
  1296.     case 'p':
  1297.     case 'P':
  1298.       prec = 6;
  1299.       break;
  1300.  
  1301.     default:
  1302.       *sizeP = 0;
  1303.       return "Bad call to MD_ATOF()";
  1304.     }
  1305.   t = atof_ieee (input_line_pointer, type, words);
  1306.   if (t)
  1307.     input_line_pointer = t;
  1308.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  1309.   for (wordP = words; prec--;)
  1310.     {
  1311.       md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
  1312.       litP += sizeof (LITTLENUM_TYPE);
  1313.     }
  1314.   return 0;
  1315. }
  1316.  
  1317. /*
  1318.  * Write out big-endian.
  1319.  */
  1320. void
  1321. md_number_to_chars (buf, val, n)
  1322.      char *buf;
  1323.      long val;
  1324.      int n;
  1325. {
  1326.  
  1327.   switch (n)
  1328.     {
  1329.  
  1330.     case 4:
  1331.       *buf++ = val >> 24;
  1332.       *buf++ = val >> 16;
  1333.     case 2:
  1334.       *buf++ = val >> 8;
  1335.     case 1:
  1336.       *buf = val;
  1337.       break;
  1338.  
  1339.     default:
  1340.       as_fatal ("failed sanity check.");
  1341.     }
  1342.   return;
  1343. }                /* md_number_to_chars() */
  1344.  
  1345. /* Apply a fixS to the frags, now that we know the value it ought to
  1346.    hold. */
  1347.  
  1348. #ifdef BFD_ASSEMBLER
  1349. int
  1350. #else
  1351. void
  1352. #endif
  1353. md_apply_fix (fixP, value)
  1354.      fixS *fixP;
  1355. #ifdef BFD_ASSEMBLER
  1356.      long *value;
  1357. #else
  1358.      long value;
  1359. #endif
  1360. {
  1361.   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  1362.   long val;
  1363.  
  1364. #ifdef BFD_ASSEMBLER
  1365.   val = *value;
  1366. #else
  1367.   val = value;
  1368. #endif
  1369.  
  1370.   assert (fixP->fx_size == 4);
  1371. #ifdef BFD_ASSEMBLER
  1372.   assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
  1373. #else
  1374.   assert (fixP->fx_r_type < NO_RELOC);
  1375. #endif
  1376.  
  1377.   fixP->fx_addnumber = val;    /* Remember value for emit_reloc */
  1378.  
  1379.   /*
  1380.    * This is a hack.  There should be a better way to
  1381.    * handle this.
  1382.    */
  1383.   if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
  1384.     {
  1385.       val += fixP->fx_where + fixP->fx_frag->fr_address;
  1386.     }
  1387.  
  1388.   switch (fixP->fx_r_type)
  1389.     {
  1390.  
  1391.     case BFD_RELOC_32:
  1392.       buf[0] = 0;        /* val >> 24; */
  1393.       buf[1] = 0;        /* val >> 16; */
  1394.       buf[2] = 0;        /* val >> 8; */
  1395.       buf[3] = 0;        /* val; */
  1396.       break;
  1397.  
  1398.     case BFD_RELOC_32_PCREL_S2:
  1399.       val = (val >>= 2) + 1;
  1400.       buf[0] |= (val >> 24) & 0x3f;
  1401.       buf[1] = (val >> 16);
  1402.       buf[2] = val >> 8;
  1403.       buf[3] = val;
  1404.       break;
  1405.  
  1406.  
  1407.     case BFD_RELOC_HI22:
  1408.       if (!fixP->fx_addsy)
  1409.     {
  1410.       buf[1] |= (val >> 26) & 0x3f;
  1411.       buf[2] = val >> 18;
  1412.       buf[3] = val >> 10;
  1413.     }
  1414.       else
  1415.     {
  1416.       buf[2] = 0;
  1417.       buf[3] = 0;
  1418.     }
  1419.       break;
  1420.  
  1421.     case BFD_RELOC_SPARC22:
  1422.       if (val & ~0x003fffff)
  1423.     {
  1424.       as_bad ("relocation overflow");
  1425.     }            /* on overflow */
  1426.       buf[1] |= (val >> 16) & 0x3f;
  1427.       buf[2] = val >> 8;
  1428.       buf[3] = val & 0xff;
  1429.       break;
  1430.  
  1431.     case BFD_RELOC_SPARC13:
  1432.       if (val & ~0x00001fff)
  1433.     {
  1434.       as_bad ("relocation overflow");
  1435.     }            /* on overflow */
  1436.       buf[2] |= (val >> 8) & 0x1f;
  1437.       buf[3] = val & 0xff;
  1438.       break;
  1439.  
  1440.  
  1441.     case BFD_RELOC_LO10:
  1442.       if (!fixP->fx_addsy)
  1443.     {
  1444.       buf[2] |= (val >> 8) & 0x03;
  1445.       buf[3] = val;
  1446.     }
  1447.       else
  1448.     buf[3] = 0;
  1449.       break;
  1450.     case BFD_RELOC_SPARC_BASE13:
  1451.       if (((val > 0) && (val & ~0x00001fff))
  1452.       || ((val < 0) && (~(val - 1) & ~0x00001fff)))
  1453.     {
  1454.       as_bad ("relocation overflow");
  1455.     }            /* on overflow */
  1456.       buf[2] |= (val >> 8) & 0x1f;
  1457.       buf[3] = val;
  1458.       break;
  1459.  
  1460.     case BFD_RELOC_SPARC_WDISP22:
  1461.       val = (val >>= 2) + 1;
  1462.       /* FALLTHROUGH */
  1463.     case BFD_RELOC_SPARC_BASE22:
  1464.       buf[1] |= (val >> 16) & 0x3f;
  1465.       buf[2] = val >> 8;
  1466.       buf[3] = val;
  1467.       break;
  1468.  
  1469.     case BFD_RELOC_NONE:
  1470.     default:
  1471.       as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);
  1472.       break;
  1473.     }
  1474.  
  1475. #ifdef BFD_ASSEMBLER
  1476.   return 1;
  1477. #endif
  1478. }
  1479.  
  1480. /* should never be called for sparc */
  1481. void
  1482. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  1483.      char *ptr;
  1484.      long from_addr;
  1485.      long to_addr;
  1486.      fragS *frag;
  1487.      symbolS *to_symbol;
  1488. {
  1489.   as_fatal ("sparc_create_short_jmp\n");
  1490. }
  1491.  
  1492. #ifdef BFD_ASSEMBLER
  1493.  
  1494. /* Translate internal representation of relocation info to BFD target
  1495.    format.  */
  1496. arelent *
  1497. tc_gen_reloc (section, fixp)
  1498.      asection *section;
  1499.      fixS *fixp;
  1500. {
  1501.   arelent *reloc;
  1502.   bfd_reloc_code_real_type code;
  1503.  
  1504.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
  1505.   assert (reloc != 0);
  1506.  
  1507.   reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  1508.   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  1509.   if (fixp->fx_pcrel == 0)
  1510.     reloc->addend = fixp->fx_addnumber;
  1511.   else
  1512.     switch (OUTPUT_FLAVOR)
  1513.       {
  1514.       case bfd_target_elf_flavour:
  1515.     reloc->addend = 0;
  1516.     break;
  1517.       case bfd_target_aout_flavour:
  1518.     reloc->addend = - reloc->address;
  1519.     break;
  1520.       default:
  1521.     /* What's a good default here?  Is there any??  */
  1522.     abort ();
  1523.       }
  1524.  
  1525.   switch (fixp->fx_r_type)
  1526.     {
  1527.     case BFD_RELOC_32:
  1528.     case BFD_RELOC_HI22:
  1529.     case BFD_RELOC_LO10:
  1530.     case BFD_RELOC_32_PCREL_S2:
  1531.     case BFD_RELOC_SPARC_BASE13:
  1532.       code = fixp->fx_r_type;
  1533.       break;
  1534.     default:
  1535.       abort ();
  1536.     }
  1537.   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  1538.   assert (reloc->howto != 0);
  1539.  
  1540.   return reloc;
  1541. }
  1542.  
  1543. #else
  1544.  
  1545. /* Translate internal representation of relocation info to target format.
  1546.  
  1547.    On sparc: first 4 bytes are normal unsigned long address, next three
  1548.    bytes are index, most sig. byte first.  Byte 7 is broken up with
  1549.    bit 7 as external, bits 6 & 5 unused, and the lower
  1550.    five bits as relocation type.  Next 4 bytes are long addend. */
  1551. /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com */
  1552. void
  1553. tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
  1554.      char *where;
  1555.      fixS *fixP;
  1556.      relax_addressT segment_address_in_file;
  1557. {
  1558.   long r_index;
  1559.   long r_extern;
  1560.   long r_addend = 0;
  1561.   long r_address;
  1562.  
  1563.   know (fixP->fx_addsy);
  1564.  
  1565.   if (!S_IS_DEFINED (fixP->fx_addsy))
  1566.     {
  1567.       r_extern = 1;
  1568.       r_index = fixP->fx_addsy->sy_number;
  1569.     }
  1570.   else
  1571.     {
  1572.       r_extern = 0;
  1573.       r_index = S_GET_TYPE (fixP->fx_addsy);
  1574.     }
  1575.  
  1576.   /* this is easy */
  1577.   md_number_to_chars (where,
  1578.               r_address = fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
  1579.               4);
  1580.  
  1581.   /* now the fun stuff */
  1582.   where[4] = (r_index >> 16) & 0x0ff;
  1583.   where[5] = (r_index >> 8) & 0x0ff;
  1584.   where[6] = r_index & 0x0ff;
  1585.   where[7] = ((r_extern << 7) & 0x80) | (0 & 0x60) | (fixP->fx_r_type & 0x1F);
  1586.  
  1587.   /* Also easy */
  1588.   if (fixP->fx_addsy->sy_frag)
  1589.     {
  1590.       r_addend = fixP->fx_addsy->sy_frag->fr_address;
  1591.     }
  1592.  
  1593.   if (fixP->fx_pcrel)
  1594.     {
  1595.       r_addend += fixP->fx_offset - r_address;
  1596.     }
  1597.   else
  1598.     {
  1599.       r_addend = fixP->fx_addnumber;
  1600.     }
  1601.  
  1602.   md_number_to_chars (&where[8], r_addend, 4);
  1603.  
  1604.   return;
  1605. }                /* tc_aout_fix_to_chars() */
  1606. #endif
  1607.  
  1608. /* should never be called for sparc */
  1609. void
  1610. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  1611.      char *ptr;
  1612.      long from_addr, to_addr;
  1613.      fragS *frag;
  1614.      symbolS *to_symbol;
  1615. {
  1616.   as_fatal ("sparc_create_long_jump\n");
  1617. }                /* md_create_long_jump() */
  1618.  
  1619. /* should never be called for sparc */
  1620. int
  1621. md_estimate_size_before_relax (fragP, segtype)
  1622.      fragS *fragP;
  1623.      segT segtype;
  1624. {
  1625.   as_fatal ("sparc_estimate_size_before_relax\n");
  1626.   return (1);
  1627. }                /* md_estimate_size_before_relax() */
  1628.  
  1629. #if 0
  1630. /* for debugging only */
  1631. static void
  1632. print_insn (insn)
  1633.      struct sparc_it *insn;
  1634. {
  1635.   char *Reloc[] =
  1636.   {
  1637.     "RELOC_8",
  1638.     "RELOC_16",
  1639.     "RELOC_32",
  1640.     "RELOC_DISP8",
  1641.     "RELOC_DISP16",
  1642.     "RELOC_DISP32",
  1643.     "RELOC_WDISP30",
  1644.     "RELOC_WDISP22",
  1645.     "RELOC_HI22",
  1646.     "RELOC_22",
  1647.     "RELOC_13",
  1648.     "RELOC_LO10",
  1649.     "RELOC_SFA_BASE",
  1650.     "RELOC_SFA_OFF13",
  1651.     "RELOC_BASE10",
  1652.     "RELOC_BASE13",
  1653.     "RELOC_BASE22",
  1654.     "RELOC_PC10",
  1655.     "RELOC_PC22",
  1656.     "RELOC_JMP_TBL",
  1657.     "RELOC_SEGOFF16",
  1658.     "RELOC_GLOB_DAT",
  1659.     "RELOC_JMP_SLOT",
  1660.     "RELOC_RELATIVE",
  1661.     "NO_RELOC"
  1662.   };
  1663.  
  1664.   if (insn->error)
  1665.     {
  1666.       fprintf (stderr, "ERROR: %s\n");
  1667.     }
  1668.   fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
  1669.   fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
  1670.   fprintf (stderr, "exp = {\n");
  1671.   fprintf (stderr, "\t\tX_add_symbol = %s\n",
  1672.        ((insn->exp.X_add_symbol != NULL)
  1673.         ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
  1674.            ? S_GET_NAME (insn->exp.X_add_symbol)
  1675.            : "???")
  1676.         : "0"));
  1677.   fprintf (stderr, "\t\tX_sub_symbol = %s\n",
  1678.        ((insn->exp.X_subtract_symbol != NULL)
  1679.         ? (S_GET_NAME (insn->exp.X_subtract_symbol)
  1680.            ? S_GET_NAME (insn->exp.X_subtract_symbol)
  1681.            : "???")
  1682.         : "0"));
  1683.   fprintf (stderr, "\t\tX_add_number = %d\n",
  1684.        insn->exp.X_add_number);
  1685.   fprintf (stderr, "}\n");
  1686.   return;
  1687. }                /* print_insn() */
  1688.  
  1689. #endif
  1690.  
  1691. /*
  1692.  * md_parse_option
  1693.  *    Invocation line includes a switch not recognized by the base assembler.
  1694.  *    See if it's a processor-specific option.  These are:
  1695.  *
  1696.  *    -bump
  1697.  *        Warn on architecture bumps.  See also -A.
  1698.  *
  1699.  *    -Av6, -Av7, -Av8, -Asparclite
  1700.  *        Select the architecture.  Instructions or features not
  1701.  *        supported by the selected architecture cause fatal errors.
  1702.  *
  1703.  *        The default is to start at v6, and bump the architecture up
  1704.  *        whenever an instruction is seen at a higher level.
  1705.  *
  1706.  *        If -bump is specified, a warning is printing when bumping to
  1707.  *        higher levels.
  1708.  *
  1709.  *        If an architecture is specified, all instructions must match
  1710.  *        that architecture.  Any higher level instructions are flagged
  1711.  *        as errors.
  1712.  *
  1713.  *        if both an architecture and -bump are specified, the
  1714.  *        architecture starts at the specified level, but bumps are
  1715.  *        warnings.
  1716.  *
  1717.  */
  1718.  
  1719. int 
  1720. md_parse_option (argP, cntP, vecP)
  1721.      char **argP;
  1722.      int *cntP;
  1723.      char ***vecP;
  1724. {
  1725.   char *p;
  1726.   const char **arch;
  1727.  
  1728.   if (!strcmp (*argP, "bump"))
  1729.     {
  1730.       warn_on_bump = 1;
  1731.  
  1732.     }
  1733.   else if (**argP == 'A')
  1734.     {
  1735.       p = (*argP) + 1;
  1736.  
  1737.       for (arch = architecture_pname; *arch != NULL; ++arch)
  1738.     {
  1739.       if (strcmp (p, *arch) == 0)
  1740.         {
  1741.           break;
  1742.         }            /* found a match */
  1743.     }            /* walk the pname table */
  1744.  
  1745.       if (*arch == NULL)
  1746.     {
  1747.       as_bad ("unknown architecture: %s", p);
  1748.     }
  1749.       else
  1750.     {
  1751.       current_architecture = (enum sparc_architecture) (arch - architecture_pname);
  1752.       architecture_requested = 1;
  1753.     }
  1754.     }
  1755.   else
  1756.     {
  1757.       /* Unknown option */
  1758.       (*argP)++;
  1759.       return 0;
  1760.     }
  1761.   **argP = '\0';        /* Done parsing this switch */
  1762.   return 1;
  1763. }                /* md_parse_option() */
  1764.  
  1765. /* We have no need to default values of symbols. */
  1766.  
  1767. /* ARGSUSED */
  1768. symbolS *
  1769. md_undefined_symbol (name)
  1770.      char *name;
  1771. {
  1772.   return 0;
  1773. }                /* md_undefined_symbol() */
  1774.  
  1775. /* Parse an operand that is machine-specific.
  1776.    We just return without modifying the expression if we have nothing
  1777.    to do. */
  1778.  
  1779. /* ARGSUSED */
  1780. void 
  1781. md_operand (expressionP)
  1782.      expressionS *expressionP;
  1783. {
  1784. }
  1785.  
  1786. /* Round up a section size to the appropriate boundary. */
  1787. long 
  1788. md_section_align (segment, size)
  1789.      segT segment;
  1790.      long size;
  1791. {
  1792.   /* Round all sects to multiple of 8 */
  1793.   return (size + 7) & ~7;
  1794. }
  1795.  
  1796. /* Exactly what point is a PC-relative offset relative TO?
  1797.    On the sparc, they're relative to the address of the offset, plus
  1798.    its size.  This gets us to the following instruction.
  1799.    (??? Is this right?  FIXME-SOON) */
  1800. long 
  1801. md_pcrel_from (fixP)
  1802.      fixS *fixP;
  1803. {
  1804.   return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
  1805. }
  1806.  
  1807. #ifndef BFD_ASSEMBLER
  1808. void 
  1809. tc_aout_pre_write_hook (headers)
  1810.      object_headers *headers;
  1811. {
  1812.   H_SET_VERSION (headers, 1);
  1813. }
  1814. #endif
  1815.  
  1816. /* end of tc-sparc.c */
  1817.